package com.example.xinding;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class SecondActivity extends AppCompatActivity {

    private static final String TAG = "SecondActivity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent intent = getIntent();
        String extra_data = intent.getStringExtra("extra_data");
        Log.d(TAG, "onCreate: 接收到的值为:" + extra_data);
        setContentView(R.layout.activity_second);
        Button btn2 = findViewById(R.id.button_2);
        btn2.setOnClickListener(v -> {
            Intent intent1 = new Intent();
            intent1.putExtra("data_return", "从activity2返回的值：hello activity1");
            setResult(RESULT_OK,  intent1);
            finish();
        });
    }

    @Override
    public void onBackPressed() {
        Intent intent = new Intent();
        intent.putExtra("data_return", "从activity的back按钮返回的");
        setResult(RESULT_OK, intent);
        finish();
    }
}